package cn.net.gemai.springboot_eureka_client_customer.config;

import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestConfig {
    /**
     * 消费方引入负载均衡Ribbon依赖
     * 并在接口调用组件上加@LoadBalanced注解，接管请求
     * 服务提供方如有多个实例时，Ribbon会根据负载算法，动态切换调用的具体实例
     * 本例子包含服务提供方service-provider 8081和8084两个实例
     */
    @LoadBalanced
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}
